<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button id="btn">复制</button>
    <script>
        btn.addEventListener('click',function(){
            // 浏览器适配模式 嗅探
            if(navigator.clipboard){
                var text='要复制的内容'
                navigator.clipboard.writeText(text)
            }
            else{
                let textarea=document.createElement('textarea')
                document.body.appendChild(textarea)
                textarea.style.position='absolute'
                textarea.style.clip='rect(0 0 0 0)'
                textarea.value='copy的内容'

                textarea.select()

                document.execCommand('copy',true)
            }
        })
    </script>
</body>
</html>